﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class lyCotrols_shoppingCartGrid : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //购物车
        DataTable shoppingCat = (DataTable)Session["ShoppingCat"];
        this.DgCat.DataSource = shoppingCat.DefaultView;
        this.DgCat.DataBind();

        //绑定删除事件
        this.DgCat.DeleteCommand += new DataGridCommandEventHandler(DgCat_DeleteCommand);
    }

    //删除DataRow中的行
    public void DgCat_DeleteCommand(Object sender, DataGridCommandEventArgs e)
    {
        //取ID
        string id = e.Item.Cells[0].Text;
        //取张数
        string code = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
        int k = e.Item.ItemIndex;

        DataTable shoppingCat = (DataTable)Session["ShoppingCat"];
        string filter = "pid = " + id;
        DataRow[] row = shoppingCat.Select("pid ='" + id + "'");
        for (int i = 0; i < row.Length; i++)
        {
            shoppingCat.Rows.Remove(row[i]);
        }
        //================
        Session["ShoppingCat"] = shoppingCat;
        this.DgCat.DataSource = ((DataTable)Session["ShoppingCat"]).DefaultView;
        this.DgCat.DataBind();
    }

}
